<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>网站公告列表页</title>
	<style>
		#page_end{
			float:left;
			width:300px;
			height:50px;
			/* margin: 0 auto; */
			margin-left:400px;
		}
		.page_style{
			width:50px;
			height:30px;
			background-color:#3477c8;
			float:left;
			margin-left:10px;
			margin-top:10px;
			margin-bottom:10px;
			text-align:center;
			line-height:30px;
		}
		.page_style a{
			color:white;
			font-size:14px;
		}
	</style>
</head>
<body>
<?php 
include_once("header.php");
$whereSql = "  1=1 ";
// $list = db_get_all("select * from news where $whereSql order by id desc");

// 定义分页原理
    $page = isset($_GET["page"]) ? $_GET["page"] : 1; // 分页页码
    $arr["page"]=$page;
    $n = 5; // 每页要显示多少条
    $m = ($page - 1) * $n;
    $arr['m']=$m;
// 求总记录数
    $sql = "select * from news order by id desc";
    $result = mysql_query($sql);
    $total = mysql_num_rows($result);
    $maxpage = ceil($total / $n);
    $arr["maxpage"]=$maxpage;
    $limit = " limit $m,$n"; // 拼接的子句要加上空格
    $sql = "select * from news order by id desc" . $limit;
    $result = mysql_query($sql);
    if ($result){
        $nums = mysql_num_rows($result);
        if ($nums >= 1){
            while ($row = mysql_fetch_assoc($result)) {
                $infos[] = $row; // 将数据库表内容存储到二维数组infos中
            }
        }else{
            $infos = array(); //此时infos变量是false的；
        }
        $arr["infos"]=$infos;
    }else {
        echo "错误：" . mysql_error($link);
    }
?>
<div class="m_ctr">
    <div class="ej_tctr">
		当前位置：<a href="index.php">首页</a> &gt; 站内公告
	</div>
    <div class="m_ctr1">
        <div class="">
            <div class="ej_rt3">
				站内公告
			</div>
            <?php 
			if(infos){
				foreach($infos as $key => $value) {?>
            <div class="newslist_t1">
                <div class="newslist_t11">
					<a href="newsshow.php?id=<?php echo $value['id'];?>">
						<?php echo $value['title'];?>
					</a>
				</div>
                <div class="newslist_t12"><?php echo substr($value["addtime"],0,10);?></div>
            </div>
            <?php 
			}
			}
			?>
        </div>
    </div>
    <div id="page_end">
        <div class="page_style"><a href="news.php?page=1">首页</a></div>
        <div class="page_style"><a href="news.php?page=<?= ($page==1)?1:$page-1;?>">上一页</a></div>
        <div class="page_style"><a href="news.php?page=<?= $page==$maxpage?$maxpage:$page+1;?>">下一页</a></div>
        <div class="page_style"><a href="news.php?page=<?= $maxpage;?>">尾页</a></div>
    </div>
</div>
<?php include_once("footer.php");?>
</body>
</html>